package com.webtest.demo;

import static org.testng.Assert.assertEquals;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.webtest.core.BaseTest;
import com.webtest.dataprovider.NSDataProvider;

public class Demo extends BaseTest {

	@BeforeTest
	public void login() {
		webtest.open("");
	//后台登陆
		webtest.type("name=login_name", "root");
		webtest.type("name=login_pass", "123456");
		webtest.click("xpath=//button[@class='btn btn-primary px-4']");

		System.out.println("成功登录");
	}
    
	@Test
	public void test1() throws Exception{
		//不再显示友情提示
		webtest.click("link=不再提示");
		Thread.sleep(1000);
	}

	
	@Test //修改公司简介
	public void test2() {
		webtest.click("link=传统后台");
        Thread.sleep(1000);

		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
		webtest.click("xpath=//i[@class='iconfont-metadmin icon-metadmin-manage']");
		webtest.click("xpath=//i[@class='list-group-item d-flex align-items-center justify-content-between py-2 pr-2 pl-2']");
		webtest.click("xpath=//i[@class='list-group-item d-flex align-items-center justify-content-between py-2 pr-2 pl-3 active']");
		webtest.type("xpath=//i[@class='edui-editor-iframeholder edui-default']", "123456");
	}

	
	@Test //添加栏目
	public void test3() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
		webtest.click("xpath=//i[@class='iconfont-metadmin icon-metadmin-column']");
		webtest.click("link= 添加");
		Thread.sleep(1000);
		webtest.type("name=name-new-0", "其他");
        Thread.sleep(1000);
		webtest.type("name=foldername-new-0", "更多资讯");
        webtest.click("link=保存");
	}

	
	@Test //切换语言
	public void test4()  {
		webtest.click("link=简体中文");
        webtest.click("link=English");
	}

	//随机改变某个栏目顺序
	@Test(dataProvider = "number", dataProviderClass = DataProvider.class)//随机改变某个栏目顺序
	public void test5(String positive, String negative) {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
		webtest.click("xpath=//i[@class='iconfont-metadmin icon-metadmin-column']");
		webtest.type("xpath=//input[@name='no_order-34'", positive);

	}

	
	@Test //删除单个栏目
	public void test6() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");

        webtest.click("xpath=//i[@class='iconfont-metadmin icon-metadmin-column']");
		webtest.click("xpath=//button[@class='btn btn-default dropdown-prompt']");
        webtest.click("xpath=//button[@class='dropdown-item btn-del-column']");
        webtest.click("link=确定");
		
	}

	
	@Test //添加管理员
	public void test7() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");

		webtest.mouseToElement("link=用户管理");
		webtest.click("link=管理员");
		webtest.click("添加管理员");
		webtest.type("name=username", "lijiajing");
		webtest.type("name=password", "20020601");
        webtest.click("link=保存");
		Thread.sleep(1000);
	}

	
	@Test //修改管理员资料
	public void test8() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
		
        webtest.click("xpath=//i[@class='iconfont-metadmin icon-metadmin-administrator']");
        webtest.click("xpath=//i[@class='dropdown-item px-3']");
        webtest.click("xpath=//button[@class='btn btn-default btn-sys']");
        webtest.type("name=admin_name", "李佳静");
        webtest.click("xpath=//button[@class='btn btn-primary']");
		
	}


	@Test //多选删除管理员
	public void test9() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
        webtest.click("xpath=//i[@class='iconfont-metadmin icon-metadmin-administrator']"); 
		WebElement num = driver.findElement(By.name("id"));
		Select s2 = new Select(num);
		s2.selectByValue("1");
		s2.selectByVisibleText("2");
		webtest.click("xpath=//button[@class='btn btn-delete-all']");
	}

	
	@Test //不勾选管理员直接删除，查看是否有弹窗
	public void test10() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
        webtest.click("xpath=//i[@class='iconfont-metadmin icon-metadmin-administrator']"); 
		webtest.click("xpath=//button[@class='btn btn-delete-all']");
        //出现弹窗
        webtest.click("xpath=//i[@class='position-relative']");
        //关掉弹窗
	}


    @Test //删除多个栏目
	public void test11() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");

        webtest.click("xpath=//i[@class='iconfont-metadmin icon-metadmin-column']");
        webtest.click("xpath=//i[@class='checkall-all custom-control-input']");
        webtest.click("xpath=//button[@class='btn btn-default']");
        webtest.click("link=确定");
		
	}

	
	@Test //不勾选直接删除栏目
	public void test12() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");

        webtest.click("xpath=//i[@class='iconfont-metadmin icon-metadmin-column']");
        webtest.click("xpath=//button[@class='btn btn-default']");
        webtest.click("link=确定");
        //出现弹窗
        webtest.click("xpath=//i[@class='position-relative']");

		
	}


    @Test //修改会员资料(保存手机号)
	public void test13() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
		
        webtest.click("xpath=//i[@class='iconfont-metadmin icon-metadmin-administrator']");
        webtest.click("xpath=//i[@class='dropdown-item px-4']");
        webtest.click("xpath=//button[@class='btn btn-default btn-edit']");
        webtest.type("name=tel", "18131570815");
        webtest.click("xpath=//button[@class='btn btn-primary']");
		
	}

    @Test //不做修改，保存会员资料，检查是否有弹窗
	public void test14() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
		
        webtest.click("xpath=//i[@class='iconfont-metadmin icon-metadmin-administrator']");
        webtest.click("xpath=//i[@class='dropdown-item px-4']");
        webtest.click("xpath=//button[@class='btn btn-default btn-edit']");
        webtest.click("xpath=//button[@class='btn btn-primary']");
		
	}


    @Test //上传图片修改会员背景
	public void test15() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
		
        webtest.click("xpath=//i[@class='iconfont-metadmin icon-metadmin-administrator']");
        webtest.click("xpath=//i[@class='dropdown-item px-4']");
        webtest.click("link=会员功能设置");
        webtest.click("xpath=//button[@class='btn btn-primary btn-file mb-0 element-visible']","C:\Users\Administrator\Desktop\li\web期末\images\9.jpg");
		webtest.click("xpath=//button[@class='btn btn-primary']");
	}

    @Test //修改网站部分基本信息
	public void test16() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
		
       webtest.mouseToElement("link=基本设置");
       webtest.click("link=基本信息");
       webtest.type("name=met_webname", "米拓网站");
       //修改元素属性
		WebElement img1 = driver.findElement(By.xpath("//div[@class='metadmin-fmbx']/dl[1]/dd/div/span/div[2]/div[1]/div/label"));
		js.executeScript("arguments[0].setAttribute('class','ljj0601');",img1);
		webtest.type("xpath='a[@class=\"ljj0601\"]'","C:\Users\Administrator\Desktop\li\web期末\images\9.jpg");
        webtest.click("link=保存");
	}

    @Test //清除缓存
	public void test17() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
		
       webtest.mouseToElement("link=清空缓存");
       webtest.click("link=系统缓存");
       Thread.sleep(1000);
	}

    @Test //检测更新
	public void test18() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
		
       webtest.click("link=检测更新");
       webtest.click("xpath=//a[@class='log_url text-help ml-2']");//网页跳转
       Thread.sleep(1000);
	}

    @Test //内容管理搜索数字
	public void test19() {
		webtest.click("link=传统后台");
        Thread.sleep(1000);
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");

		webtest.click("xpath=//i[@class='iconfont-metadmin icon-metadmin-manage']");
		webtest.type("name=search", "1");//不显示弹窗
	}

    @Test //内容管理搜索“我们”
	public void test20() {
		webtest.click("link=传统后台");
        Thread.sleep(1000);
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");

		webtest.click("xpath=//i[@class='iconfont-metadmin icon-metadmin-manage']");
		webtest.type("name=search", "我们");//显示对应模块
	}


    @Test //设置默认栏目
	public void test21() {
		webtest.click("link=传统后台");
        Thread.sleep(1000);
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");

		webtest.click("xpath=//i[@class='iconfont-metadmin icon-metadmin-manage']");
		webtest.selectByVisibleText("xpath=//select[@name='default_show_column']", "-公司简介");
		
		assertEquals(webtest.isDisplayed("xpath=//div[@class='success show']"), true);
	}

    @Test //还原空的回收站
	public void test22() {
		webtest.click("link=传统后台");
        Thread.sleep(1000);
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");

		webtest.click("xpath=//i[@class='iconfont-metadmin icon-metadmin-manage']");
		webtest.click("xpath=//a[@class='btn-content-recycle text-content']");
        webtest.click("xpath=//button[@class='btn btn-primary']");//出现弹窗
        webtest.click("xpath=//i[@class='position-relative']");

	}


    @Test //导出中文语言包
	public void test23() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
        
		webtest.click("link=多语言");
        webtest.click("xpath=//a[@class='btn btn-default mb-2']");
        webtest.switchWindow(0);
		

	}

    @Test //关闭前台语言切换
	public void test24() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
        
		webtest.click("link=多语言");
        webtest.click("link=语言设置");
        webtest.click("xpath=//s[@class='switchery switchery-default']");
        webtest.click("xpath=//button[@class='btn btn-primary']");

	}

    @Test //编辑后台语言
	public void test25() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
        
		webtest.click("link=多语言");
        webtest.click("link=后台语言");
        webtest.click("xpath=//button[@class='btn btn-default mb-2 btn-edit']");
        webtest.type("name=name", "中文");
        webtest.click("xpath=//button[@class='btn btn-primary']");

	}


    @Test //备份数据
	public void test26() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
        
		webtest.mouseToElement("link=安全设置");
        webtest.click("link=备份与恢复");
        webtest.click("xpath=//button[@class='btn btn-primary btn-backdata']");
        webtest.click("xpath=//button[@class='btn btn-primary']");
        webtest.click("link=备份");

	}

    @Test //在未登录的情况下下载插件
	public void test27() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
        
		webtest.mouseToElement("link=应用插件");
        webtest.click("link=免费插件");
        webtest.click("xpath=//s[@class='ml-2']");//显示弹窗
        webtest.click("xpath=//i[@class='position-relative']");


	}

    @Test //插件搜索栏输入数字
	public void test28() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
        
		webtest.mouseToElement("link=应用插件");
        webtest.click("link=免费插件");
        webtest.type("name=keyword", "1");


	}

    @Test //插件搜索栏输入“工具”
	public void test29() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
        
		webtest.mouseToElement("link=应用插件");
        webtest.click("link=免费插件");
        webtest.type("name=keyword", "工具");


	}

    @Test //插件界面注册
	public void test29() {
		webtest.click("link=传统后台");
		webtest.click("xpath=//button[@class='btn btn-default no-prompt']");
        
		webtest.mouseToElement("link=应用插件");
        webtest.click("link=免费插件");
        webtest.click("xpath=//button[@class='btn btn-default']");
        webtest.type("name=username", "root");
        webtest.type("name=password", "123456");
        webtest.click("link=登录");
        


	}


	
	@AfterTest
	public void test_quit() {
		webtest.click("link=后台");
		webtest.click("xpath=//button[@class='btn btn-primary dropdown-toggle']");
		webtest.click("link=退出");
	}
}
